﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using CodeFirstMVC3.Domain.Model;
using System.Linq;

namespace CodeFirstMVC3.DataAccess.Model
{
    [Table("Member")]
    public class Member : IMember
    {
        public int Id { get; set; }

        [ForeignKey("Role")]
        public int RoleId { get; set; }

        [Required]
        public string Username { get; set; }

        [Required]
        public string Password { get; set; }

        [Required]
        public bool Active { get; set; }

        [ForeignKey("RoleId")]
        public virtual Role Role { get; set; }

        public virtual IEnumerable<User> Users { get; set; }

        [NotMapped]
        IRole IMember.Role
        {
            get { return this.Role; }
            set { Role = value as Role; }
        }

        IEnumerable<IUser> IMember.Users
        {
            get { return this.Users; }
            set { this.Users = value.Cast<User>(); }
        }
    }
}
